package com.sinosoft.perfect.system._.action;

import java.sql.SQLException;

import com.sinosoft.perfect.common.system.BaseAction;
import com.sinosoft.perfect.system._.service.ILoginService;
import com.sinosoft.perfect.system._.vo.LoginUser;

@SuppressWarnings("serial")
public class LoginAction extends BaseAction{
	
	private ILoginService loginservice;
	
	private String username;
	
	private String frameFolder;
	
	public ILoginService getLoginservice() {
		return loginservice;
	}

	public void setLoginservice(ILoginService loginservice) {
		this.loginservice = loginservice;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	public String getFrameFolder() {
		return frameFolder;
	}

	public void setFrameFolder(String frameFolder) {
		this.frameFolder = frameFolder;
	}

	public String login() {
		try {
			LoginUser loginUser = loginservice.queryUserInfoAndLog(username, request.getRemoteAddr());
			session.put("user", loginUser);
			session.put("tempFolder", request.getSession().getServletContext().getRealPath("temp"));
		} catch (SQLException e) {
			e.printStackTrace();
			session.put("exceptionInfoClass", e);
			return "exceptionOperateAction";
		}
		return "loginCenterOpenWindow";
	}
	
	public String loginCenterOpenWindowMethod() {
		this.setFrameFolder(((LoginUser)session.get("user")).getFrameModelWay());
		return "frame";
	}
	
	public String logout() {
		try {
			loginservice.logoutUpdateLogInfo(((LoginUser) session.get("user")).getTloginLog().getLogId());
		} catch (SQLException e) {
			e.printStackTrace();
			session.put("exceptionInfoClass", e);
			return "exceptionOperateAction";
		}finally{
			session.invalidate();
		}
		return "loginPage";
	}
}
